<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('编辑模板')" />
    <th:block th:include="include :: CodeMirror-css" />
    <style>
    .CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
  </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-template-edit" th:object="${file}">
            <input name="url" th:field="*{url}" type="hidden">
            <div class="form-group">    
                <div class="col-sm-12">
                	<textarea id="content" name="content" th:field="*{content}" class="form-control">
                	
                	</textarea>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: CodeMirror-js" />
    <script th:inline="javascript">
        var prefix = ctx + "cms/template";
       
        
        window.onload = function() {
            editor = CodeMirror.fromTextArea(document.getElementById("content"), {
              mode: "text/html",
              extraKeys: {"Ctrl-Space": "autocomplete"},
              value: document.documentElement.innerHTML
            });
        };
        
        
        $("#form-template-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
        	document.getElementById("content").value=editor.getValue();
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-template-edit').serialize());
            }
        }

    </script>
</body>
</html>